include("shared.lua")

if !ConVarExists("mining_MineralViewDistance") then
	CreateClientConVar("mining_MineralViewDistance",3000,true,false)
end

if !ConVarExists("mining_MineralFadeDistance") then
	CreateClientConVar("mining_MineralFadeDistance",2500,true,false)
end

//Turn off the damned outline!
function ENT:DrawEntityOutline( size )
end

//Only draw if in range
function ENT:Draw()
	
	//Get Camera Position
	if ValidEntity(LocalPlayer()) then //For some reason, LocalPlayer() sometimes goes nil so, here we are...
		ViewPos = LocalPlayer():GetViewModel():GetPos()
	end
	
	local ViewDist = GetConVarNumber("mining_MineralViewDistance")
	local FadeDist = GetConVarNumber("mining_MineralFadeDistance")
	local Distance = ViewPos:Distance(self:GetPos())
	
	//Check Distance from Camera
	if Distance < ViewDist then
		//Outside the fade range?
		if Distance > FadeDist then
			self:SetColor(255,255,255,(255-(255*((Distance-FadeDist)/(ViewDist-FadeDist)))))
		else
			self:SetColor(255,255,255,255)
		end
		self:DrawModel()
	end
end
